#include <stdio.h>
#include <stdlib.h>

int main() {
    FILE *fp;
    char ch;

    fp = fopen("..\\test-data.txt", "a+");
    if (fp == NULL) {
        printf("open file fail\n");
        printf("press any key to skip\n");
        getchar();
        // exit(0)表示程序正常退出
        // exit(1)/exit(-1)表示程序异常退出
        exit(0);
    }

    printf("enter a char to file:\n");
    ch = getchar();
    while (ch != '\n') {
        fputc(ch, fp);
        ch = getchar();
    }

    fclose(fp);

    return 0;
}